// Copyright (C) joyinter
// All rights reserved.
// 
// Author : Lu Rong
// Date   : 2005-01-26

#ifndef __TRENCH_H_CLIENT_MAIN__
#define __TRENCH_H_CLIENT_MAIN__

#pragma once

#include <common\ui\wnd.h>
#include <common\ui\wndcontainer.h>
#include <common\ui\scrollbar.h>
#include <common\ui\imagectrl.h>
#include <common\netmsg\netmsg.h>
#include <common\netmsg\gameiddef.h>
#include <server\csanalyse\csanalyse.h>

class CJoyTrenchHBarWrapper;
class CJoyWndContainer;
class CJoyRoomPage;
class CJoyTrench;
class CJoyTrenchPageCtrl;

namespace JoyTrenchElem
{
class CJoyTrenchPane;
class CJoyTrenchInfo;
class CJoyTrenchRoleGroupPanel;
class CJoyTrenchList;
class CJoyTrenchListItem;
};

//##ModelId=44C4B5DB01C5
class CJoyCSPlayerItem : 
	public CCSGamePlayer,
	public CJoyCtrl
{
protected:
	friend class CJoyTrench;
	friend class JoyTrenchElem::CJoyTrenchInfo;

	//##ModelId=44C4B5DB01D5
	CJoyTrench	*m_trench;

	//##ModelId=44C4B5DB035B
	enum ITEM_STATE
	{
		//##ModelId=44C4B5DB036B
		ITEM_DEF,
		//##ModelId=44C4B5DB036C
		ITEM_NORMAL,
		//##ModelId=44C4B5DB036D
		ITEM_HOVER,
		//##ModelId=44C4B5DB037A
		ITEM_DISABLE
	};
	//##ModelId=44C4B5DB01DA
	JoyTrenchElem::CJoyTrenchRoleGroupPanel *m_rolePanel;

	//##ModelId=44C4B5DB01DF
	Color m_iconColorDef;
	//##ModelId=44C4B5DB01E7
	Color m_iconColorNormal;
	//##ModelId=44C4B5DB01EC
	Color m_killColor;
	//##ModelId=44C4B5DB01F8
	Color m_bekillColor;
	//##ModelId=44C4B5DB01FD
	Color m_frameColor1;
	//##ModelId=44C4B5DB0204
	Color m_frameColor2;
	//##ModelId=44C4B5DB0214
	Color m_clickFrameColor;
	//##ModelId=44C4B5DB0219
	Color m_borderColor;

	//##ModelId=44C4B5DB0223
	ITEM_STATE	m_state;
	//##ModelId=44C4B5DB0227
	bool		m_bSel;

	// data
	//##ModelId=44C4B5DB0232
	int				m_level;
	//##ModelId=44C4B5DB0233
	int				m_ladder;
	//##ModelId=44C4B5DB0243
	CStringW		m_battleGroup;

	//##ModelId=44C4B5DB0247
	virtual void CM_LoadSkin(CJoyXmlElement * pSkinElem);
	//##ModelId=44C4B5DB0261
    virtual void CM_Draw(Graphics& graph);
	//##ModelId=44C4B5DB0271
    virtual void CM_Mouse(MouseMessage msg, const CPoint& pt);
	//##ModelId=44C4B5DB0290
	virtual void CM_SelItem(bool b);

	//##ModelId=44C4B5DB029F
	void ClearPlayerData();

public:
	//##ModelId=44C4B5DB02AF
	void AttachPlayerInfo(const CCSGamePlayer &player);
	//##ModelId=44C4B5DB02BF
	void DetachPlayerInfo();

public:
	//##ModelId=44C4B5DB02CE
	CJoyCSPlayerItem();
	//##ModelId=44C4B5DB02DE
	CJoyCSPlayerItem(int nUserID, CString strNickName, UINT nPlayerId, CS_PLAYER_ROLE cpr, CString strPlayerCSName, UINT nKillCount, UINT nBekillCount, LONG nPlayTime);
	//##ModelId=44C4B5DB031C
	virtual ~CJoyCSPlayerItem() {}
	//##ModelId=44C4B5DB031E
	void operator = (CCSGamePlayer &gamePlayer);

	//##ModelId=44C4B5DB033C
	void ClearState() { m_state = ITEM_DEF; }

	//##ModelId=44C4B5DB033D
	const CStringW GetNickName() { return m_nickName; }
	//##ModelId=44C4B5DB033E
	const CStringW GetPlayName() { return m_playerCSName; }
	//##ModelId=44C4B5DB033F
	const UINT GetKillCount() { return m_killCount; }
	//##ModelId=44C4B5DB0340
	const UINT GetBekillCount() { return m_bekillCount; }
	//##ModelId=44C4B5DB0341
	const LONG GetPlayTime() { return m_playTime; }

	//##ModelId=44C4B5DB034B
	virtual bool Create(CJoyCtrl* parent, const CRect& area);
};

//##ModelId=44C4B5DC002E
class CJoyTrench :
	public CJoyWnd
{
	DECLARE_DYNAMIC(CJoyTrench)

public:
	//##ModelId=44C4B5DC02CE
	typedef void (CJoyWnd::*PSelItem)(CJoyCSPlayerItem *item);

protected:
	friend class CJoyRoomPage;
	friend class CJoyCSPlayerItem;
	friend class JoyTrenchElem::CJoyTrenchInfo;
	friend class CJoyTrenchPageCtrl;
	friend class CJoyTrenchCheckBox;
	friend class JoyTrenchElem::CJoyTrenchRoleGroupPanel;

	//##ModelId=44C4B5DC0031
	CJoyTrenchPageCtrl	*m_pageCtrl;

	// added by lr for cs server 2005-05-18
	//##ModelId=44C4B5DC003F
	CS_PROC_INFO	m_csProcInfo;
	//##ModelId=44C4B5DC0043
	bool		m_bEndAnalyzeThread;
	//##ModelId=44C4B5DC0044
	bool		m_bEndCSProc;

	// the cs server
	//##ModelId=44C4B5DC004E
	UINT		m_srcUser;
	//##ModelId=44C4B5DC004F
	UINT		m_svrPort;
	// basic data
	//##ModelId=44C4B5DC005D
	UINT		m_roomId;
	//##ModelId=44C4B5DC005E
	UINT		m_trenchId;
	//##ModelId=44C4B5DC0060
	CStringW	m_trenchName;
	//##ModelId=44C4B5DC006E
	CStringW	m_gameName;
	//##ModelId=44C4B5DC0073
	CStringW	m_csMapName;	
	//##ModelId=44C4B5DC007D
	UINT		m_maxPlayerCount;
	// changing data
	//##ModelId=44C4B5DC007E
	UINT		m_playingCount;
	//##ModelId=44C4B5DC008C
	UINT		m_spectatorCount;

	//##ModelId=44C4B5DC008E
	CJoyCSPlayerItem	*m_selItem;
	//##ModelId=44C4B5DC009D
	PSelItem			m_onSelItem;

	// interface
	//##ModelId=44C4B5DC00A2
	CJoyTrenchHBarWrapper *m_hBarWrapper;
	//##ModelId=44C4B5DC00AC
	CJoyScrollBar *m_vBar;
	//##ModelId=44C4B5DC00B1
	CJoyScrollBar *m_hBar;

	//##ModelId=44C4B5DC00BC
	CJoyWndContainer *m_container;
	//##ModelId=44C4B5DC00C0
	CRect m_areaContainer;
	//##ModelId=44C4B5DC00CB
	int m_leftVisible;
	//##ModelId=44C4B5DC00CC
	int m_topVisible;
	//##ModelId=44C4B5DC00DA
	CRect m_areaVScroll;
	//##ModelId=44C4B5DC00DB
	CRect m_areaHScroll;
	//##ModelId=44C4B5DC00EA
	int m_scrollStep; 

	//##ModelId=44C4B5DC00EC
	CJoyImagePtr	m_imgHead_def;
	//##ModelId=44C4B5DC00FD
	CJoyImagePtr	m_imgHead_ct;
	//##ModelId=44C4B5DC0102
	CJoyImagePtr	m_imgHead_t;

	//##ModelId=44C4B5DC010C
	JoyTrenchElem::CJoyTrenchInfo				*m_trenchInfo;
	//##ModelId=44C4B5DC011A
	JoyTrenchElem::CJoyTrenchRoleGroupPanel		*m_t_GroupPanel;
	//##ModelId=44C4B5DC011F
	JoyTrenchElem::CJoyTrenchRoleGroupPanel		*m_ct_GroupPanel;
	//##ModelId=44C4B5DC0129
	JoyTrenchElem::CJoyTrenchList				*m_trenchList;

	//##ModelId=44C4B5DC012E
	CJoyButton *m_btnJoinBattle;

	//##ModelId=44C4B5DC02D0
	typedef CList<CJoyCSPlayerItem *>	CItemList;

	// free items
	//##ModelId=44C4B5DC0139
	CItemList	m_t_freeItems;
	//##ModelId=44C4B5DC0149
	CItemList	m_ct_freeItems;

	// using items
	//##ModelId=44C4B5DC014E
	CItemList	m_t_items;
	//##ModelId=44C4B5DC0158
	CItemList	m_ct_items;

	//##ModelId=44C4B5DC02DF
	typedef CMap<UINT, UINT, CJoyCSPlayerItem *, CJoyCSPlayerItem *> CCSPlayerIdMap;

	//##ModelId=44C4B5DC015D
	CCSPlayerIdMap	m_playerIdMap; 

	//##ModelId=44C4B5DC016B
	CJoyXmlElement *m_skinPlayerView;
	//##ModelId=44C4B5DC0177
	int	m_itemcountDef;

	//##ModelId=44C4B5DC0178
	virtual void CE_VScroll(CJoyScrollBar *, CJoyScrollBar::SCROLLBAR_MESSAGE, float &);
	//##ModelId=44C4B5DC0196
	virtual void CE_HScroll(CJoyScrollBar *, CJoyScrollBar::SCROLLBAR_MESSAGE, float &);
	//##ModelId=44C4B5DC01B5
	virtual void CM_LoadSkin(CJoyXmlElement * pSkinElem);
//	virtual void CM_SelItem(CJoyCSPlayerItem *item);

	//##ModelId=44C4B5DC01C5
	virtual CJoyCSPlayerItem * CreateItem();

	//##ModelId=44C4B5DC02EE
	enum ITEM_ROLE { ROLE_CT = 1, ROLE_T = 2 };
	//##ModelId=44C4B5DC01C7
	void AddItemDef(const ITEM_ROLE &ir);
	//##ModelId=44C4B5DC01D4
	void RemoveItem(CJoyCSPlayerItem *item, ITEM_ROLE role);
	//##ModelId=44C4B5DC01E5
	CJoyCSPlayerItem * AssignItem(CItemList &free, CItemList &use, ITEM_ROLE role);
	//##ModelId=44C4B5DC0203
	void RecycleItem(CItemList &free, CItemList &use, CJoyCSPlayerItem * &item, ITEM_ROLE role);

public:
	//##ModelId=44C4B5DC0224
	CJoyRoomPage	*m_room;

	//##ModelId=44C4B5DC0232
	void InitializeTrench();
	//##ModelId=44C4B5DC0233
	void UninitializeTrench();

	//##ModelId=44C4B5DC0242
	void AssignPlayer(CCSGamePlayer &player);
	//##ModelId=44C4B5DC0244
	void RecycleAllItems();

	//##ModelId=44C4B5DC0251
	void CM_BattleClick(CJoyButton *);
//	void SetSelItemEvent(CJoyWnd *pWnd, PSelItem pOnSel);
	//##ModelId=44C4B5DC0261
	void SelItem(CJoyCSPlayerItem *item);
	//##ModelId=44C4B5DC0271
	void UnselItem();

public:
	//##ModelId=44C4B5DC0272
	CJoyTrench(void);
	//##ModelId=44C4B5DC0280
	virtual ~CJoyTrench(void);

	//##ModelId=44C4B5DC0290
	const CStringW GetGameName() { return m_gameName; }
	//##ModelId=44C4B5DC0291
	const CStringW GetCSMapName() { return m_csMapName; }
	//##ModelId=44C4B5DC0292
	const UINT GetMaxPlayerCount() { return m_maxPlayerCount; }

	//##ModelId=44C4B5DC029F
	void SendTrench();
	//##ModelId=44C4B5DC02A0
	void RecvTrench();

public:
	DECLARE_MESSAGE_MAP()
	//##ModelId=44C4B5DC02A1
	afx_msg int OnCreate(LPCREATESTRUCT lpCreateStruct);
	//##ModelId=44C4B5DC02AF
	afx_msg void OnSize(UINT nType, int cx, int cy);
};

#endif  // __TRENCH_H_CLIENT_MAIN__
